package com.lin.csdn.service.impl;

import com.lin.csdn.dao.impl.TalkDao;
import com.lin.csdn.dao.impl.UserDao;
import com.lin.csdn.utils.DateView;
import com.lin.csdn.utils.ResultSplit;

import java.util.List;

public class TalkService {

    TalkDao talkDao=new TalkDao();
    ResultSplit splits=new ResultSplit();
    UserDao userDao=new UserDao();
    DateView dateView=new DateView();

    //查询对方的聊天记录
    public List<Object> search(String userName,String targetName){
        int userid=userDao.findId(userName);
        int targetId=userDao.findId(targetName);
        Object result=talkDao.search(userid,targetId);
        return splits.resultSplit(result);
    }

    //查询自己的聊天记录
    public List<Object> searchUserTalk(String userName,String targetName){
        int userid=userDao.findId(userName);
        int targetId=userDao.findId(targetName);
        Object result=talkDao.searchUserTalk(userid,targetId);
        return splits.resultSplit(result);
    }


    //发送新的聊天
    public void addTalk(String userName,String targetName,String context){
        int userid=userDao.findId(userName);
        int targetId=userDao.findId(targetName);
        String date=dateView.getDate();
        talkDao.addTalk(userid,targetId,date,context);
    }
}
